<template>
    <div>
        <h1>人员列表</h1>
        <h1>count组件求和为{{ sum }}</h1>
        <h1>列表中第一个人的名字是{{ firstPersonName }}</h1>
        <input type="text" v-model="name" placeholder="请输入名字">
        <button @click="addPerson">添加</button>
        <button @click="addPersonWang">添加王姓成员</button>
        <ul>
            <li v-for="person in personList" :key="person.id">{{person.name}}</li>
            
        </ul>
    </div>
</template>
<script>
// import {mapState} from 'vuex'
import {nanoid} from 'nanoid'
export default {
    name:'person',
    data(){
        return {
            name:''
        }
    },
    computed:{
        // ...mapState(['personList'])
        personList(){
            return this.$store.state.personAbout.personList
        },
        sum(){
            return this.$store.state.countAbout.sum
        },

        firstPersonName(){
            return this.$store.getters['personAbout/firstPersonName']
        }
    },
    methods:{
        addPerson(){
            const personObj = {id:nanoid(),name:this.name}
            console.log(personObj)
            this.$store.commit('personAbout/ADD_PERSON',personObj)
            this.name=''
        },
        addPersonWang(){
            const personObj = {id:nanoid(),name:this.name}
            this.$store.dispatch('personAbout/addPersonWang',personObj)
            this.name=''
        }
    }
}
</script>
